package cn.gjculture.shopping.api.service.impl;

import cn.gjculture.shopping.api.entity.Return;
import cn.gjculture.shopping.api.entity.Token;
import cn.gjculture.shopping.api.entity.User;
import cn.gjculture.shopping.api.service.LoginService;
import cn.gjculture.shopping.api.service.TokenService;
import cn.gjculture.shopping.api.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;



@Service
public class LoginServiceImpl implements LoginService {

    @Autowired
    UserService userService;

    @Autowired
    TokenService tokenService;

    @Override
    public boolean loginMgr(String userName, String password, Return<Token> ret) {
        User user= userService.queryByName(userName);
        if(user!=null&&user.getPassword().equals(password)){
            Token token=tokenService.getToken(user.getUserId());
            user.setPassword("");
            token.setUser(user);
            ret.setData(token);
            return true;
        }else {
            ret.getCommon().setError("账户或密码错误");
        }
        return false;
    }
}
